<?php

/**
 * MVM_MALL 网上商店系统  会员等级管理
 * ============================================================================
 * 版权所有 (C) 2007-2010 www.mvmmall.com，并保留所有权利。
 * 网站地址: http://www.mvmmall.com
 * ----------------------------------------------------------------------------
 * 这是一个免费开源的软件；这意味着您可以在不用于商业目的的前提下对程序代码
 * 进行修改、使用和再发布。
 * ============================================================================
 * $Author:  www.mvmmall.com  $
 * $Date: 2008-07-12 $
 * $Id: grade.inc.php www.mvmmall.com$
 * ---------------------------------------------
*/

if(!defined('MVMMALL') || !defined('IN_ADMINCP')) exit('Access Denied');
if($action=='list'){
	$result    = $db->query("SELECT * FROM `{$tablepre}grade_table` ORDER BY degree ASC ");
	while ($rt = $db->fetch_array($result)) {
		$rt['show_price'] = $rt['show_price']==1 ? $lang['yes'] : $lang['no'];
		$rt['edit']       = "admincp.php?module=$module&action=edit&uid=$rt[group_id]";
		$rt['del']        = "admincp.php?module=$module&action=del&uid=$rt[group_id]";
		$grade_rt[]       = $rt;
	}
	require_once template('grade');
	footer();
} elseif ($action=='add'){
	if($setp==1 && $_POST) {
		for ($i=0;$i<count($rank);$i++){
			$grade_act = $rank[$i].'act';
			$rank_list.=$rank[$i].':'.implode(":", $$grade_ac).',';
		}
		$degree     = $degree ? (int)$degree:10;
		$rank_list  = substr($rank_list,0,-1);
		$rows     = array(
		'group_name' => $group_name,
		'max_points' => $max_points,
		'min_points' => $min_points,
		'discount'   => $discount,
		'show_price' => $show_price,
		'rank_list'  => $rank_list,
		'degree'     => $degree
		);
		$db->insert("{$tablepre}grade_table",dhtmlchars($rows));
		$cache->put_cache('grade');
		admin_msg('success','admincp.php?module=grade&action=list');
	} else {
		drop_check(1,'show_price');
		$discount = 100;
		require_once MVMMALL_ROOT.'./include/rank_list.inc.php';
		require_once template('grade_add');
		footer();
	}
}
elseif ($action=='edit' && is_numeric($uid)){
	if($setp==1 && $_POST) {
		for ($i=0;$i<count($rank);$i++){
			$grade_act = $rank[$i].'act';
			$rank_list.=$rank[$i].':'.implode(":", $$grade_act).',';
		}
		$rank_list = substr($rank_list,0,-1);
		$rows      = array(
		'group_name' => $group_name,
		'max_points' => $max_points,
		'min_points' => $min_points,
		'discount'   => $discount,
		'show_price' => $show_price,
		'rank_list'  => $rank_list,
		'degree'     => $degree
		);
		$db->update("{$tablepre}grade_table",dhtmlchars($rows),"group_id='$uid'");
		$cache->put_cache('grade');
		admin_msg('success','admincp.php?module=grade&action=list');
	} else {
		$rt_rank  = $db->get_one("SELECT * FROM `{$tablepre}grade_table` WHERE group_id='$uid'");
		$rank     = explode(',',$rt_rank['rank_list']);
		@extract($rt_rank,EXTR_OVERWRITE);
		drop_check($show_price,'show_price');
		unset($rank_list);
		require_once MVMMALL_ROOT.'./include/rank_list.inc.php';
		require_once template('grade_add');
		footer();
	}
} elseif ($action=='del' && is_numeric($uid)){
	$db->query("DELETE FROM `{$tablepre}grade_table` WHERE group_id = '$uid'");
	$cache->put_cache('grade');
	admin_msg('success','admincp.php?module=grade&action=list');
} else {
    admin_msg('pass_worng');
}